package com.xiaoxu.spzx.manager.controller;

import com.github.pagehelper.PageInfo;
import com.xiaoxu.spzx.manager.service.BrandService;
import com.xiaoxu.spzx.model.entity.product.Brand;
import com.xiaoxu.spzx.model.vo.common.Result;
import com.xiaoxu.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value="/admin/product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    //分类品牌----------> 1.查询到所有品牌

    @GetMapping("/findAll")
    public Result findAll(){

       List<Brand> list = brandService.findAll();

       return  Result.build(list,ResultCodeEnum.SUCCESS);
    }


    //分页品牌管理
    @GetMapping("/{page}/{limit}")
    public Result findBrandPage(@PathVariable("page")Integer page, @PathVariable("limit") Integer limit){


     PageInfo<Brand> pageInfo  = brandService.findBrandPage(page,limit);

         return Result.build(pageInfo,ResultCodeEnum.SUCCESS);
    }
    //添加
    @PostMapping("save")
    public Result insertBrand(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    //修改
    @PutMapping("updateById")
    public Result updateBrand(@RequestBody Brand brand){
        brandService.updateById(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    //删除
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id){

        brandService.deleteBrandById(id);

        return Result.build(null,ResultCodeEnum.SUCCESS);
    }


}
